# Copyright 2023 Ant Group Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_python//python:defs.bzl", "py_library", "py_test")
load("@pybind11_bazel//:build_defs.bzl", "pybind_extension")

package(default_visibility = ["//visibility:public"])

exports_files(
    [
        "exported_symbols.lds",
        "version_script.lds",
    ],
    visibility = ["//visibility:private"],
)

pybind_extension(
    name = "libserving",
    srcs = ["libserving.cc"],
    linkopts = select({
        "@bazel_tools//src/conditions:darwin": [
            "-Wl,-exported_symbols_list,$(location //secretflow_serving_lib:exported_symbols.lds)",
        ],
        "//conditions:default": [
            "-Wl,--version-script,$(location //secretflow_serving_lib:version_script.lds)",
        ],
    }),
    deps = [
        ":exported_symbols.lds",
        ":version_script.lds",
        "//secretflow_serving/ops",
        "//secretflow_serving/ops:graph_version",
        "@yacl//yacl/base:exception",
    ],
)

py_library(
    name = "protos",
    srcs = [
        "attr_pb2.py",
        "bundle_pb2.py",
        "compute_trace_pb2.py",
        "data_type_pb2.py",
        "feature_pb2.py",
        "graph_pb2.py",
        "link_function_pb2.py",
        "op_pb2.py",
        "//secretflow_serving/protos:attr_py_proto",
        "//secretflow_serving/protos:bundle_py_proto",
        "//secretflow_serving/protos:compute_trace_py_proto",
        "//secretflow_serving/protos:data_type_py_proto",
        "//secretflow_serving/protos:feature_py_proto",
        "//secretflow_serving/protos:graph_py_proto",
        "//secretflow_serving/protos:link_function_py_proto",
        "//secretflow_serving/protos:op_py_proto",
    ],
)

py_library(
    name = "api",
    srcs = [
        "api.py",
        ":protos",
    ],
    data = [
        ":libserving.so",
    ],
)

py_library(
    name = "init",
    srcs = [
        "__init__.py",
        "version.py",
        ":api",
        ":protos",
    ],
)

py_test(
    name = "api_test",
    srcs = ["api_test.py"],
    deps = [
        ":init",
    ],
)
